package com.song.controller;

import com.song.pojo.User;
import jakarta.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Author 宋伟宁
 * @Date 2024/1/3
 * @Version 1.0
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Value("${server.port}")
    private String port;

    private static final  String url="http://product-9000/product/";
    @Resource //@Autowired
    private RestTemplate restTemplate;

    @GetMapping("/")
    public String hello(){
        String template = this.restTemplate.getForObject(url,String.class);
        return "端口号的"+this.port+"调用了"+template;
    }

    @PostMapping("/")
    public String add(@RequestBody User user){
      String mess= this.restTemplate.postForObject(url+"add",user,String.class);
      return this.port+mess;
    }
}
